package com.imachen.order.rocket.impl;

import com.imachen.order.rocket.RocketMQProducerService;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

@Service
public class RocketMQProducerServiceImpl implements RocketMQProducerService {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Value("${rocketmq.producer.send-message-timeout}")
    private Integer messageTimeOut;

    @Override
    public SendResult sendMsg(String msgBody) {
        SendResult result = rocketMQTemplate.syncSend("order-topic", MessageBuilder.withPayload(msgBody).build());
        return result;
    }

    @Override
    public void sendDelayMsg(String msgBody, Integer delayLevel) {
        rocketMQTemplate.syncSend("order-topic",MessageBuilder.withPayload(msgBody).build(),messageTimeOut,delayLevel);
    }
}